/*
** my_list.c for asm in /home/vanet_c//proj-kw
** 
** Made by charles-edouard vanet
** Login   <vanet_c@epitech.net>
** 
** Started on  Thu Dec  6 16:34:01 2012 charles-edouard vanet
** Last update Sat Dec 15 19:07:51 2012 charles-edouard vanet
*/

#include	"../includes/asm.h"

int		my_put_in_list(t_list **list, char *str)
{
  t_list	*elem;

  if ((elem = malloc(sizeof(t_list))) == NULL)
    return (1);
  elem->name = epur_file_name(my_strdup(str));
  elem->file = NULL;
  elem->tmp_for_label = NULL;
  elem->next = *list;
  *list = elem;
  return (0);
}

t_list		*my_param_in_list(int ac, char **av)
{
  int		i;
  t_list	*list;

  list = NULL;
  i = 1;
  while (i < ac)
    i++;
  while (i > 1)
    {
      if (my_put_in_list(&list, av[i - 1]) == 1)
	my_error("", "", "Can't perform malloc.\n", 1);
      i--;
    }
  return (list);
}

void	my_free_one_tlist(t_list *list)
{
  free(list->name);
  my_free_file_list(&(list->file));
  free(list);
}

void		my_free_list(t_list *list)
{
  t_list	*tmp;

  tmp = list;
  if (list->tmp_for_label != NULL)
    my_free_tab(list->tmp_for_label);
  while (tmp != NULL)
    {
      free(list->name);
      my_free_file_list(&(list->file));
      tmp = tmp->next;
      free(list);
      list = tmp;
    }
}
